<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ws client</title>
</head>
<body>
<p style="border:1px solid black;width: 600px;height: 500px" id="talkMsg"></p>
<input id="message" /><button id="sendBtn" onclick="sendMsg()">发送</button>
</body>
<script>
    // let socket = new WebSocket("ws://localhost:8080/ws1")
    let socket = new WebSocket("ws://localhost:8080/ws2")
    socket.onopen = () => {
        console.log("WebSocket 已连接");
    };
    socket.onclose = () => {
        console.log("WebSocket 已断开");
    };
    socket.onerror = (error) => {
        console.error("WebSocket 错误：", error);
    };
    socket.onmessage = function (message) {
        document.getElementById("talkMsg").innerHTML = message.data
    }
    function sendMsg() {
        socket.send(document.getElementById("message").value)
        document.getElementById("message").value=""
    }
</script>
</html>